// pages/login/login.ts
import { ComponentWithStore } from "mobx-miniprogram-bindings"
import userStore from "../../store/userStore"
ComponentWithStore({
  /**
   *绑定userStore中的数据 
   */
  storeBindings: {
    store: userStore,
    fields: ["token"],
    actions: ["login"]
  },
  /**
   * 页面的初始数据
   */
  data: {

  },
  methods: {
    /**
     * @description 点击授权登录的回调函数
     */
    handlelogin() {
      /*wx.login({
        success: async (result: WechatMiniprogram.LoginSuccessCallbackResult) => {
          if (result.code) {
            try {
              const { data: { data: { token } } } = await loginAPI(result.code)
              console.log(token);
              setStorage<string>("token", token)
            } catch (error) {
              wx.showToast({ icon: "error", title: error.message })
            }
          } else {
            wx.showToast({ icon: "error", title: "授权失败重新授权" })
          }
        },
        fail: () => {
          wx.showToast({ icon: "error", title: "用户授权失败" })
        }
      })*/
      userStore.login()
    },
  },
})